/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SessionTracker.DataAccess;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 *
 * @author TuMap90TVT
 */
public class Connections {
public static Connection connectSQL() throws Exception {
        /**
         * Register driver and getConnection();
         */
        Connection conn = null;
            /** Creates a new instance of DBHelper */
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
            conn = DriverManager.getConnection(connString());

    
        return conn;
    }

    /**
    * This static method is used to get a SQL Server Connection String from file connection.cfg
    * @return  the SQL Server Connection String from file config.inf
    **/
    public static String connString()
    {
        Properties p = new Properties();
        try
        {
            FileInputStream fin = new FileInputStream("config.inf");
            p.load(fin);
        }
        catch(Exception e)
        {
           return "";
        }

        String server = p.getProperty("ServerID");
        String instance = p.getProperty("Instance");
        String port = p.getProperty("Port");
        String databaseName = p.getProperty("Database");
        String username = p.getProperty("Username");
        String password = p.getProperty("Password");

        return "jdbc:sqlserver://" + server + ":" + port +
                ";databaseName=" + databaseName +
                ";User=" + username +
                ";Password=" + password;
    }
}